package com.c.ctgproject.ui.collect

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.c.ctgproject.R
import com.c.ctgproject.adapter.guang.BatteryOutDetailAdapter
import com.c.ctgproject.adapter.guang.PartOutDetailAdapter
import com.c.ctgproject.base.BaseActivityV2
import com.c.ctgproject.databinding.ActivityPartBeanOutBinding
import com.c.ctgproject.entity.guang.BatteryOutEntity
import com.c.ctgproject.entity.guang.PartOutDetailEntity
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.http.MyObserverHandlerLoading
import com.c.ctgproject.utils.*
import com.c.ctgproject.wiget.common.CarInfoLayout

/**
 *作者:LiBW
 *创建日期: 2021/9/17
 *描述: 零部件出库单
 */
class PartBeanOutActivity : BaseActivityV2() {
    private val mBinding by lazy { ActivityPartBeanOutBinding.inflate(layoutInflater) }
    override fun getLayout() = mBinding.root

    private val orderId by lazy { intent.getIntExtra(MyConstants.ORDER_ID, -1) }
    override fun event() {
        ApiMethods.apiSubscribe(ApiMethods.retrofit.partOutDetail(orderId), MyObserverHandlerLoading(this, loading) {
            MyLog.d("新建零部件出库单详情回调:$it")
            val data = getGson().fromJson(it, PartOutDetailEntity::class.java).data
            data?.let { bean ->
                mBinding.mContainer1.addView(CarInfoLayout(this, "出库单号", bean.orderNo.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "开单人", bean.createPersonName.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "开单时间", bean.createTime.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "客户", bean.customer.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "备注", bean.remark.noDataHandler()))
                customer=bean.customer.handlerNull()
            }

            //列表
            data?.items?.let { list ->
                list.forEach { bean ->
                    partsIdList.add(bean.orderId)
                }
                val adapter = PartOutDetailAdapter(this, list)
                mBinding.mRecyclerView.adapter = adapter
                mBinding.mRecyclerView.layoutManager = LinearLayoutManager(this)
            }
        })
    }

    private var customer = ""
    private var partsIdList = ArrayList<Int>()

    override fun click() {
//        mBinding.mConfirmBTN.setOnClickListener {
//            val map = HashMap<String, Any>()
//            map["customer"] = customer
//            map["partsIdList"] = partsIdList
//            ApiMethods.apiSubscribe(ApiMethods.retrofit.partOutSubmit(handlerBody(map)), MyObserverHandlerLoading(this, loading) {
//                MyLog.d("回调:$it")
//                showToast("提交成功")
//                finish()
//            })
//        }
    }
}